/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import BLL.*;
import DAL.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Emmanuel
 */
public class ElBoliche extends javax.swing.JFrame {

    /**
     * Creates new form ElBoliche
     */
    public ElBoliche() {
        initComponents();   
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jLabel1 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        btComprarCredito = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtRut = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btBuscar = new javax.swing.JButton();
        btComprar = new javax.swing.JButton();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        mingresar = new javax.swing.JMenuItem();
        mmodificar = new javax.swing.JMenuItem();
        mborrar = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        Stock = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 0, 48)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel1.setText("  Bienvenidos");

        btComprarCredito.setText("Comprar a credito");
        btComprarCredito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btComprarCreditoActionPerformed(evt);
            }
        });

        jLabel2.setText("Nombre");

        jLabel3.setText("Rut");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(jTable1);

        btBuscar.setText("Buscar");
        btBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBuscarActionPerformed(evt);
            }
        });

        btComprar.setText("Comprar");
        btComprar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btComprarActionPerformed(evt);
            }
        });

        jMenu3.setText("Clientes");

        mingresar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        mingresar.setText("Ingresar");
        mingresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mingresarActionPerformed(evt);
            }
        });
        jMenu3.add(mingresar);

        mmodificar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        mmodificar.setText("Modificar");
        mmodificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mmodificarActionPerformed(evt);
            }
        });
        jMenu3.add(mmodificar);

        mborrar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        mborrar.setText("Borrar");
        mborrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mborrarActionPerformed(evt);
            }
        });
        jMenu3.add(mborrar);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("Lista Clientes");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuBar2.add(jMenu3);

        Stock.setText("Productos");
        Stock.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        Stock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StockActionPerformed(evt);
            }
        });

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Ingresar");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        Stock.add(jMenuItem4);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Modificar");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        Stock.add(jMenuItem2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Borrar");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        Stock.add(jMenuItem3);

        jMenuItem7.setText("Lista Productos");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        Stock.add(jMenuItem7);

        jMenuBar2.add(Stock);
        jMenuBar2.add(jMenu4);

        setJMenuBar(jMenuBar2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addGap(20, 20, 20)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtRut, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                                    .addComponent(txtNombre)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(36, 36, 36)
                                .addComponent(jLabel1)))
                        .addGap(19, 19, 19)
                        .addComponent(btBuscar)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btComprar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btComprarCredito)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 395, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btBuscar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btComprarCredito)
                    .addComponent(btComprar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void mingresarActionPerformed(java.awt.event.ActionEvent evt) {                                          
//En este menu item se puede ingresar los Clientes con con el metodo agregarClientes
 //que se encuentra en la clse del package BLL que se llama Agregar
        this.dispose();
        agregarClientes i=new agregarClientes ();
        i.setVisible(true);
        // TODO add your handling code here:
    }                                         

    private void mmodificarActionPerformed(java.awt.event.ActionEvent evt) {                                           
//En este menu item se puede ingresar los Clientes con con el metodo modificarClientes
 //que se encuentra en la clse del package BLL que se llama Modificar
        this.dispose();
        modificarClientes modificar= new modificarClientes();
        modificar.setVisible(true);
        // TODO add your handling code here:
    }                                          

    private void mborrarActionPerformed(java.awt.event.ActionEvent evt) {                                        
      //En este menu item se puede borrar los productos con con el metodo borrarClientes
 //que se encuentra en la clase del package BLL que se llama Quitar 
        this.dispose();
        borrarClientes borrar =new borrarClientes();
        borrar.setVisible(true);
        // TODO add your handling code here:
    }                                       

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
//En este menu item se puede ingresar los productos con con el metodo agregarProducto
 //que se encuentra en la clase del package BLL que se llama Agregar
        
        this.dispose();
        agregarProducto stock =new agregarProducto();
        stock.setVisible(true);
        
        // TODO add your handling code here:
    }                                          

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
 //En este menu item se puede actualizar los productos con con el metodo modificarProducto
 //que se encuentra en la clse del package BLL que se llama Modificar
        this.dispose();
         modificarProducto m=new modificarProducto();
         m.setVisible(true);
   
        // TODO add your handling code here:
    }                                          

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
 //En este menu item se puede borrar los productos con con el metodo borrarProducto
 //que se encuentra en la clse del package BLL que se llama Quitar
        this.dispose();
        borrarProducto bp =new borrarProducto();
        bp.setVisible(true);
        // TODO add your handling code here:
    }                                          

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                           
//En es te menu item ocupo el jframe pasra ver los clientes ingresado los campos  de la tabla clientes
        this.dispose();
        VerClientes v =new VerClientes();
        v.setVisible(true);
        // TODO add your handling code here:
    }                                          

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        //En este menu item ocupo el jframe para ver los prouctos ingresados en los campos de la tabla productosd 
        this.dispose();
           VerProductos v=new VerProductos();
           v.setVisible(true);
        
        // TODO add your handling code here:
    }                                          

    private void StockActionPerformed(java.awt.event.ActionEvent evt) {                                      

    
// TODO add your handling code here:
    }                                     

    private void btBuscarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        DefaultTableModel listaClientes =new DefaultTableModel();
        listaClientes.addColumn("Rut");
        listaClientes.addColumn("Nombre");
        listaClientes.addColumn("Credito");
        this.jTable1.setModel(listaClientes);

        Consultar consultar =new Consultar();
        //Dentro del try hacemos un nuevo objeto llamado consulta que despues lo colocamos dentro de unaa fila dentro del
        //Jtable que permite ver en la fila 0 por ejemplo el rut del cliente a tavez de la base de datos con el resulset 
        //que la cargamos a listaClientes.addRow como muestra el PDF TP1_XII_v1
        try{
            ResultSet r =consultar.consultaClienteEstado(this.txtRut.getText(),this.txtNombre.getText());

            String[] fila=new String[3];
            while(r.next()){
                
                fila[0]=r.getString("rut_cli");
                fila[1]=r.getString("nombre");
                if((r.getString("estado")).equals("1")){fila[2]="Activo";}
                else{fila[2]="Inactivo";}
                listaClientes.addRow(fila);
         
            }
        }
        catch(SQLException e){
        
        }
            
    }                                        

    private void btComprarCreditoActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        int row = this.jTable1.getSelectedRow();
        String credito=this.jTable1.getValueAt(row, 2).toString();
        if(credito.equals("Activo")){
            String rut=this.jTable1.getValueAt(row, 0).toString();
        }
        else{
            
        }
        this.dispose();
        agregarVenta av=new agregarVenta();
        av.setVisible(true);
        // TODO add your handling code here:
    }                                                

    private void btComprarActionPerformed(java.awt.event.ActionEvent evt) {                                          
        int row = this.jTable1.getSelectedRow();
        String rut=this.jTable1.getValueAt(row, 0).toString();
        
        //this.dispose();
        agregarVenta av=new agregarVenta();
        av.setVisible(true);
        // TODO add your handling code here:
    }                                         

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ElBoliche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ElBoliche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ElBoliche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ElBoliche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ElBoliche().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JMenu Stock;
    private javax.swing.JButton btBuscar;
    private javax.swing.JButton btComprar;
    private javax.swing.JButton btComprarCredito;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JMenuItem mborrar;
    private javax.swing.JMenuItem mingresar;
    private javax.swing.JMenuItem mmodificar;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtRut;
    // End of variables declaration                   
}
